package com.example.administrator.myproject.merchant

import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.util.Log
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import android.widget.Toast


import cn.bmob.v3.BmobQuery
import cn.bmob.v3.exception.BmobException
import cn.bmob.v3.listener.QueryListener
import com.example.administrator.myproject.R
import com.example.administrator.myproject.bean.BobmBean

class Details : AppCompatActivity(), View.OnClickListener {
    private var name: TextView? = null
    private var money: TextView? = null
    private var coum: TextView? = null
    private var details: TextView? = null
    private var imageView: ImageView? = null
    private var moeny: String? = null
    private var type: String? = null
    private val TAG = "Details"
    private fun getObject(objectId: String?) {
        var bmobQuery: BmobQuery<BobmBean> = BmobQuery()
        bmobQuery.getObject(objectId, object : QueryListener<BobmBean>() {
            override fun done(bobmBean: BobmBean, ex: BmobException?) {
                Log.i(Details.TAG, "done: "+bobmBean.toString())
                if (ex == null) {
                    name!!.text = bobmBean.name
                    if (bobmBean.name!!.equals("拌饭")) {
                        imageView!!.setImageDrawable(resources.getDrawable(R.drawable.laodiexie))
                    } else if (bobmBean.name!!.equals("米饭")) {
                        imageView!!.setImageDrawable(resources.getDrawable(R.drawable.refeng))
                    } else if (bobmBean.name!!.equals("米线")) {
                        imageView!!.setImageDrawable(resources.getDrawable(R.drawable.nanxie))
                    } else if (bobmBean.name!!.equals("面")) {
                        imageView!!.setImageDrawable(resources.getDrawable(R.drawable.kuzi_9_fen))
                    } else {
                        imageView!!.setImageDrawable(resources.getDrawable(R.drawable.mian_fan))
                    }
                    money!!.text = bobmBean.money.toString()
                    coum!!.text = "库存：" + bobmBean.coum!!
                    details!!.text = bobmBean.explain
                    type = bobmBean.type
                    moeny = bobmBean.money.toString()
                    Toast.makeText(this@Details, "查询成功", Toast.LENGTH_LONG).show()
                } else {
                    Toast.makeText(this@Details, ex.message, Toast.LENGTH_LONG).show()
                }
            }
        })
    }
    override fun onCreate(savedInstanceState: Bundle?) {

        super.onCreate(savedInstanceState)
        setContentView(R.layout.details_view)
        imageView = findViewById(R.id.details_iv)
        name = findViewById(R.id.details_tv1)
        money = findViewById(R.id.details_tv2)
        coum = findViewById(R.id.details_tv3)
        details = findViewById(R.id.details_tv4)
        val ObjectId = intent.getStringExtra("objectId")
        val bmobQuery = BmobQuery<BobmBean>()
        println(ObjectId)
        getObject(ObjectId)

    }


    override fun onClick(view: View) {
        when (view.id) {

        }
    }

    companion object {
        private const val TAG = "Details"
    }
}
